﻿@using Abp.Extensions
@model MyCompanyName.AbpZeroTemplate.Web.Areas.Mpa.Models.Common.IPermissionsEditViewModel
@helper CreatePermissionTreeItems(string parentName)
{
    var permissions = Model.Permissions.Where(p => p.ParentName == parentName || (p.ParentName.IsNullOrEmpty() && parentName.IsNullOrEmpty())).ToList();
    if (!permissions.Any())
    {
        return;
    }
    
    <ul>
        @foreach (var permission in permissions)
        {
            var selected = Model.GrantedPermissionNames.Contains(permission.Name);
            <li id="@permission.Name" class="jstree-open" data-jstree='{"selected": @selected.ToString().ToLower()}'>
                @permission.DisplayName
                @CreatePermissionTreeItems(permission.Name)
            </li>
        }
    </ul>
}
<div class="permission-tree">
    @CreatePermissionTreeItems(null)
</div>